import java.io.IOException;
import java.lang.InterruptedException;
import java.util.Scanner;

public class Utility {
    public Utility() {
    }

    /**
     * 将一个字符串拆分成字母，挨个打印
     *
     * @param alphaWait 字母之间等待的时间（毫秒）
     * @param endWait   输出结束后等待的时间（毫秒）
     * @param str       要输出的字符串
     * @param needLine  是否换行
     * @throws InterruptedException
     */
    public void waitPrint(int alphaWait, int endWait, String str, boolean needLine)
            throws InterruptedException {
        for (int i = 0; i < str.length(); i++) {
            System.out.print(str.charAt(i));
            Thread.sleep(alphaWait);
        }
        Thread.sleep(endWait);
        if (needLine) {
            System.out.println();
        }
    }

    /**
     * 清除控制台的内容
     * @throws IOException
     * @throws InterruptedException
     */
    public void clearConsole()
            throws IOException, InterruptedException {
        new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
    }

    /**
     * @param questions 问题
     * @return 用户选择的编号
     * @throws InterruptedException
     */
    public int question(String... questions)
        throws InterruptedException {
        System.out.println();
        waitPrint(100, 100, "此时，你可以：", true);
        for(int i=0; i<questions.length; i++){
            waitPrint(100, 100, (i+1)+"..."+questions[i], true);
        }
        System.out.print("请做出选择：");
        Scanner sc = new Scanner(System.in);
        return sc.nextInt();
    }
}
